<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>冒泡排序</title>
</head>
<body>
    
</body>
</html>

<script>

let tempArr = [81, 94, 11, 96, 12, 35, 17, 95, 28, 58, 41, 75, 15];
    function bubblesort (arr) {
        let len = arr.length;  //13

        function swap(m, n) {
            let temp = arr[m];
            arr[m] = arr[n];
            arr[n] = temp;
            
        }

        for(let i=len -1; i >= 0; i--) {
            for(let j=0; j<i;j++) {
                if(arr[j] > arr[j+1]) {
                    swap(j, j+1)
                }
            }
        }

        return arr
    }

    console.log(bubblesort(tempArr))
</script>